package com.slz3.business.module.templateExample.temStyle1.service;

import com.slz3.business.frame.enums.ValidFlag;
import com.slz3.business.frame.module.Repositorys;
import com.slz3.business.frame.module.Services;
import com.slz3.business.frame.steward.PageableSteward;
import com.slz3.business.module.templateExample.temStyle1.domain.TemStyle1;
import com.slz3.business.module.templateExample.temStyle1.domain.TemStyle1Factory;
import com.slz3.business.module.templateExample.temStyle1.steward.TemStyle1Specification;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import org.springframework.util.MultiValueMap;

import java.util.*;

@Slf4j
@Service
public class TemStyle1ServiceImpl implements TemStyle1Service {
    @Override
    public TemStyle1 save(TemStyle1 temStyle1) {
        return Repositorys.temStyle1.save(TemStyle1Factory.initBaseFields(temStyle1));
    }
    @Override
    public Page<TemStyle1> page(MultiValueMap<String, String> params) {
        Page<TemStyle1> temStyle1Page = Repositorys.temStyle1.findAll(
                TemStyle1Specification.findJoin(params), PageableSteward.extract(params)
        );
        return temStyle1Page;
    }


    @Override
    public TemStyle1 modify(TemStyle1 temStyle1New) {
        return Repositorys.temStyle1.saveAndFlush(TemStyle1Factory.initBaseFields(temStyle1New));
    }

    @Override
    public Optional<TemStyle1> single(UUID uuid) {
        return Repositorys.temStyle1.findById(uuid);
    }

    @Override
    public List<TemStyle1> findAllByUuids(Iterable<UUID> uuids) {
        return Repositorys.temStyle1.findAllById(uuids);
    }

    @Override
    public List<TemStyle1> delete(List<TemStyle1> temStyle1List) {
        temStyle1List.stream().forEach(item -> {
            item.setValidFlag(ValidFlag.DEL);
            TemStyle1Factory.initBaseFields(item);
        });
        return Services.temStyle1Transactional.batchModify(temStyle1List);
    }

}
